﻿using System.Net.Sockets;
using System.Runtime.CompilerServices;

namespace Letter.Net.Extensions;

public static class SocketExtension
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingReuseAddress(this Socket socket, bool reuseAddress)
    {
        socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, reuseAddress);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingLingerState(this Socket socket, LingerOption option)
    {
        socket.LingerState = option;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingKeepAlive(this Socket socket, bool keepAlive)
    {
        socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, keepAlive);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingNoDelay(this Socket socket, bool noDelay)
    {
        socket.NoDelay = noDelay;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingRcvBufferSize(this Socket socket, int rcvBufferSize)
    {
        socket.ReceiveBufferSize = rcvBufferSize;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingSndBufferSize(this Socket socket, int sndBufferSize)
    {
        socket.SendBufferSize = sndBufferSize;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingRcvTimeout(this Socket socket, int rcvTimeout)
    {
        socket.ReceiveTimeout = rcvTimeout;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void SettingSndTimeout(this Socket socket, int sndTimeout)
    {
        socket.SendTimeout = sndTimeout;
    }
}
